package demo.spring.aop.author;


import demo.spring.aop.author.Inter.CommonParent;
import demo.spring.aop.author.Inter.CommonParentImpl;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.DeclareParents;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class DeclareParentsAspect {

    //demo.spring.aop.service..* 代表demo.spring.aop.service包和子包下的所有类
    //这样声明了service包中的类都会引入一个CommonParent父接口，并用CommonParentImpl实现，形成一个代理对象commonParent
    @DeclareParents(value="demo.spring.aop.service..*", defaultImpl= CommonParentImpl.class)
    private CommonParent commonParent;



    @Before("execution (* demo.spring.aop.service..*.*(..)) && this(commonParent)")
    public void beforeUserService(CommonParent commonParent) {

            log.info(commonParent.getClass().toString());
            commonParent.doSomething();
    }



}
